package org.admanager.piadlpattern.plugin.diagram.providers;

import java.util.HashSet;
import java.util.IdentityHashMap;
import java.util.Map;
import java.util.Set;

import org.admanager.piadladmanagement.plugin.piadladmanagement.PiadladmanagementPackage;
import org.admanager.piadlpattern.plugin.diagram.edit.parts.CBAPatternEditPart;
import org.admanager.piadlpattern.plugin.diagram.edit.parts.PComponent2EditPart;
import org.admanager.piadlpattern.plugin.diagram.edit.parts.PComponentEditPart;
import org.admanager.piadlpattern.plugin.diagram.edit.parts.PComponentPort2EditPart;
import org.admanager.piadlpattern.plugin.diagram.edit.parts.PComponentPortAttachedRoleEditPart;
import org.admanager.piadlpattern.plugin.diagram.edit.parts.PComponentPortDelegatedPortsEditPart;
import org.admanager.piadlpattern.plugin.diagram.edit.parts.PComponentPortEditPart;
import org.admanager.piadlpattern.plugin.diagram.edit.parts.PConnector2EditPart;
import org.admanager.piadlpattern.plugin.diagram.edit.parts.PConnectorEditPart;
import org.admanager.piadlpattern.plugin.diagram.edit.parts.PConnectorRole2EditPart;
import org.admanager.piadlpattern.plugin.diagram.edit.parts.PConnectorRoleDelegatedRolesEditPart;
import org.admanager.piadlpattern.plugin.diagram.edit.parts.PConnectorRoleEditPart;
import org.admanager.piadlpattern.plugin.diagram.edit.parts.PConstraintEditPart;
import org.admanager.piadlpattern.plugin.diagram.edit.parts.PElementMultiplicityEditPart;
import org.admanager.piadlpattern.plugin.diagram.edit.parts.PElementRolesEditPart;
import org.admanager.piadlpattern.plugin.diagram.edit.parts.PMultiplicityEditPart;
import org.admanager.piadlpattern.plugin.diagram.edit.parts.PRoleEditPart;
import org.admanager.piadlpattern.plugin.diagram.part.PiADLADManagementMetamodelDiagramEditorPlugin;
import org.eclipse.core.runtime.IAdaptable;
import org.eclipse.emf.ecore.EClass;
import org.eclipse.emf.ecore.EClassifier;
import org.eclipse.emf.ecore.ENamedElement;
import org.eclipse.emf.ecore.EStructuralFeature;
import org.eclipse.gmf.runtime.emf.type.core.ElementTypeRegistry;
import org.eclipse.gmf.runtime.emf.type.core.IElementType;
import org.eclipse.jface.resource.ImageDescriptor;
import org.eclipse.jface.resource.ImageRegistry;
import org.eclipse.swt.graphics.Image;

/**
 * @generated
 */
public class PiADLADManagementMetamodelElementTypes {

	/**
	 * @generated
	 */
	private PiADLADManagementMetamodelElementTypes() {
	}

	/**
	 * @generated
	 */
	private static Map/*[org.eclipse.gmf.runtime.emf.type.core.IElementType, org.eclipse.emf.ecore.ENamedElement]*/elements;

	/**
	 * @generated
	 */
	private static ImageRegistry imageRegistry;

	/**
	 * @generated
	 */
	private static Set/*[org.eclipse.gmf.runtime.emf.type.core.IElementType]*/KNOWN_ELEMENT_TYPES;

	/**
	 * @generated
	 */
	public static final IElementType CBAPattern_1000 = getElementType("org.admanager.piadlpattern.plugin.diagram.CBAPattern_1000"); //$NON-NLS-1$
	/**
	 * @generated
	 */
	public static final IElementType PComponent_2013 = getElementType("org.admanager.piadlpattern.plugin.diagram.PComponent_2013"); //$NON-NLS-1$
	/**
	 * @generated
	 */
	public static final IElementType PComponentPort_2014 = getElementType("org.admanager.piadlpattern.plugin.diagram.PComponentPort_2014"); //$NON-NLS-1$
	/**
	 * @generated
	 */
	public static final IElementType PConnector_2015 = getElementType("org.admanager.piadlpattern.plugin.diagram.PConnector_2015"); //$NON-NLS-1$
	/**
	 * @generated
	 */
	public static final IElementType PConnectorRole_2016 = getElementType("org.admanager.piadlpattern.plugin.diagram.PConnectorRole_2016"); //$NON-NLS-1$
	/**
	 * @generated
	 */
	public static final IElementType PMultiplicity_2017 = getElementType("org.admanager.piadlpattern.plugin.diagram.PMultiplicity_2017"); //$NON-NLS-1$
	/**
	 * @generated
	 */
	public static final IElementType PRole_2018 = getElementType("org.admanager.piadlpattern.plugin.diagram.PRole_2018"); //$NON-NLS-1$
	/**
	 * @generated
	 */
	public static final IElementType PComponent_3011 = getElementType("org.admanager.piadlpattern.plugin.diagram.PComponent_3011"); //$NON-NLS-1$
	/**
	 * @generated
	 */
	public static final IElementType PComponentPort_3012 = getElementType("org.admanager.piadlpattern.plugin.diagram.PComponentPort_3012"); //$NON-NLS-1$
	/**
	 * @generated
	 */
	public static final IElementType PConnector_3013 = getElementType("org.admanager.piadlpattern.plugin.diagram.PConnector_3013"); //$NON-NLS-1$
	/**
	 * @generated
	 */
	public static final IElementType PConnectorRole_3014 = getElementType("org.admanager.piadlpattern.plugin.diagram.PConnectorRole_3014"); //$NON-NLS-1$
	/**
	 * @generated
	 */
	public static final IElementType PConstraint_3015 = getElementType("org.admanager.piadlpattern.plugin.diagram.PConstraint_3015"); //$NON-NLS-1$
	/**
	 * @generated
	 */
	public static final IElementType PElementRoles_4011 = getElementType("org.admanager.piadlpattern.plugin.diagram.PElementRoles_4011"); //$NON-NLS-1$
	/**
	 * @generated
	 */
	public static final IElementType PElementMultiplicity_4012 = getElementType("org.admanager.piadlpattern.plugin.diagram.PElementMultiplicity_4012"); //$NON-NLS-1$
	/**
	 * @generated
	 */
	public static final IElementType PComponentPortDelegatedPorts_4013 = getElementType("org.admanager.piadlpattern.plugin.diagram.PComponentPortDelegatedPorts_4013"); //$NON-NLS-1$
	/**
	 * @generated
	 */
	public static final IElementType PComponentPortAttachedRole_4014 = getElementType("org.admanager.piadlpattern.plugin.diagram.PComponentPortAttachedRole_4014"); //$NON-NLS-1$
	/**
	 * @generated
	 */
	public static final IElementType PConnectorRoleDelegatedRoles_4015 = getElementType("org.admanager.piadlpattern.plugin.diagram.PConnectorRoleDelegatedRoles_4015"); //$NON-NLS-1$

	/**
	 * @generated
	 */
	private static ImageRegistry getImageRegistry() {
		if (imageRegistry == null) {
			imageRegistry = new ImageRegistry();
		}
		return imageRegistry;
	}

	/**
	 * @generated
	 */
	private static String getImageRegistryKey(ENamedElement element) {
		return element.getName();
	}

	/**
	 * @generated
	 */
	private static ImageDescriptor getProvidedImageDescriptor(
			ENamedElement element) {
		if (element instanceof EStructuralFeature) {
			EStructuralFeature feature = ((EStructuralFeature) element);
			EClass eContainingClass = feature.getEContainingClass();
			EClassifier eType = feature.getEType();
			if (eContainingClass != null && !eContainingClass.isAbstract()) {
				element = eContainingClass;
			} else if (eType instanceof EClass
					&& !((EClass) eType).isAbstract()) {
				element = eType;
			}
		}
		if (element instanceof EClass) {
			EClass eClass = (EClass) element;
			if (!eClass.isAbstract()) {
				return PiADLADManagementMetamodelDiagramEditorPlugin
						.getInstance().getItemImageDescriptor(
								eClass.getEPackage().getEFactoryInstance()
										.create(eClass));
			}
		}
		// TODO : support structural features
		return null;
	}

	/**
	 * @generated
	 */
	public static ImageDescriptor getImageDescriptor(ENamedElement element) {
		String key = getImageRegistryKey(element);
		ImageDescriptor imageDescriptor = getImageRegistry().getDescriptor(key);
		if (imageDescriptor == null) {
			imageDescriptor = getProvidedImageDescriptor(element);
			if (imageDescriptor == null) {
				imageDescriptor = ImageDescriptor.getMissingImageDescriptor();
			}
			getImageRegistry().put(key, imageDescriptor);
		}
		return imageDescriptor;
	}

	/**
	 * @generated
	 */
	public static Image getImage(ENamedElement element) {
		String key = getImageRegistryKey(element);
		Image image = getImageRegistry().get(key);
		if (image == null) {
			ImageDescriptor imageDescriptor = getProvidedImageDescriptor(element);
			if (imageDescriptor == null) {
				imageDescriptor = ImageDescriptor.getMissingImageDescriptor();
			}
			getImageRegistry().put(key, imageDescriptor);
			image = getImageRegistry().get(key);
		}
		return image;
	}

	/**
	 * @generated
	 */
	public static ImageDescriptor getImageDescriptor(IAdaptable hint) {
		ENamedElement element = getElement(hint);
		if (element == null) {
			return null;
		}
		return getImageDescriptor(element);
	}

	/**
	 * @generated
	 */
	public static Image getImage(IAdaptable hint) {
		ENamedElement element = getElement(hint);
		if (element == null) {
			return null;
		}
		return getImage(element);
	}

	/**
	 * Returns 'type' of the ecore object associated with the hint.
	 * 
	 * @generated
	 */
	public static ENamedElement getElement(IAdaptable hint) {
		Object type = hint.getAdapter(IElementType.class);
		if (elements == null) {
			elements = new IdentityHashMap/*[org.eclipse.gmf.runtime.emf.type.core.IElementType, org.eclipse.emf.ecore.ENamedElement]*/();

			elements.put(CBAPattern_1000,
					PiadladmanagementPackage.eINSTANCE.getCBAPattern());

			elements.put(PComponent_2013,
					PiadladmanagementPackage.eINSTANCE.getPComponent());

			elements.put(PComponentPort_2014,
					PiadladmanagementPackage.eINSTANCE.getPComponentPort());

			elements.put(PConnector_2015,
					PiadladmanagementPackage.eINSTANCE.getPConnector());

			elements.put(PConnectorRole_2016,
					PiadladmanagementPackage.eINSTANCE.getPConnectorRole());

			elements.put(PMultiplicity_2017,
					PiadladmanagementPackage.eINSTANCE.getPMultiplicity());

			elements.put(PRole_2018,
					PiadladmanagementPackage.eINSTANCE.getPRole());

			elements.put(PComponent_3011,
					PiadladmanagementPackage.eINSTANCE.getPComponent());

			elements.put(PComponentPort_3012,
					PiadladmanagementPackage.eINSTANCE.getPComponentPort());

			elements.put(PConnector_3013,
					PiadladmanagementPackage.eINSTANCE.getPConnector());

			elements.put(PConnectorRole_3014,
					PiadladmanagementPackage.eINSTANCE.getPConnectorRole());

			elements.put(PConstraint_3015,
					PiadladmanagementPackage.eINSTANCE.getPConstraint());

			elements.put(PElementRoles_4011,
					PiadladmanagementPackage.eINSTANCE.getPElement_Roles());

			elements.put(PElementMultiplicity_4012,
					PiadladmanagementPackage.eINSTANCE
							.getPElement_Multiplicity());

			elements.put(PComponentPortDelegatedPorts_4013,
					PiadladmanagementPackage.eINSTANCE
							.getPComponentPort_DelegatedPorts());

			elements.put(PComponentPortAttachedRole_4014,
					PiadladmanagementPackage.eINSTANCE
							.getPComponentPort_AttachedRole());

			elements.put(PConnectorRoleDelegatedRoles_4015,
					PiadladmanagementPackage.eINSTANCE
							.getPConnectorRole_DelegatedRoles());
		}
		return (ENamedElement) elements.get(type);
	}

	/**
	 * @generated
	 */
	private static IElementType getElementType(String id) {
		return ElementTypeRegistry.getInstance().getType(id);
	}

	/**
	 * @generated
	 */
	public static boolean isKnownElementType(IElementType elementType) {
		if (KNOWN_ELEMENT_TYPES == null) {
			KNOWN_ELEMENT_TYPES = new HashSet/*[org.eclipse.gmf.runtime.emf.type.core.IElementType]*/();
			KNOWN_ELEMENT_TYPES.add(CBAPattern_1000);
			KNOWN_ELEMENT_TYPES.add(PComponent_2013);
			KNOWN_ELEMENT_TYPES.add(PComponentPort_2014);
			KNOWN_ELEMENT_TYPES.add(PConnector_2015);
			KNOWN_ELEMENT_TYPES.add(PConnectorRole_2016);
			KNOWN_ELEMENT_TYPES.add(PMultiplicity_2017);
			KNOWN_ELEMENT_TYPES.add(PRole_2018);
			KNOWN_ELEMENT_TYPES.add(PComponent_3011);
			KNOWN_ELEMENT_TYPES.add(PComponentPort_3012);
			KNOWN_ELEMENT_TYPES.add(PConnector_3013);
			KNOWN_ELEMENT_TYPES.add(PConnectorRole_3014);
			KNOWN_ELEMENT_TYPES.add(PConstraint_3015);
			KNOWN_ELEMENT_TYPES.add(PElementRoles_4011);
			KNOWN_ELEMENT_TYPES.add(PElementMultiplicity_4012);
			KNOWN_ELEMENT_TYPES.add(PComponentPortDelegatedPorts_4013);
			KNOWN_ELEMENT_TYPES.add(PComponentPortAttachedRole_4014);
			KNOWN_ELEMENT_TYPES.add(PConnectorRoleDelegatedRoles_4015);
		}
		return KNOWN_ELEMENT_TYPES.contains(elementType);
	}

	/**
	 * @generated
	 */
	public static IElementType getElementType(int visualID) {
		switch (visualID) {
		case CBAPatternEditPart.VISUAL_ID:
			return CBAPattern_1000;
		case PComponentEditPart.VISUAL_ID:
			return PComponent_2013;
		case PComponentPortEditPart.VISUAL_ID:
			return PComponentPort_2014;
		case PConnectorEditPart.VISUAL_ID:
			return PConnector_2015;
		case PConnectorRoleEditPart.VISUAL_ID:
			return PConnectorRole_2016;
		case PMultiplicityEditPart.VISUAL_ID:
			return PMultiplicity_2017;
		case PRoleEditPart.VISUAL_ID:
			return PRole_2018;
		case PComponent2EditPart.VISUAL_ID:
			return PComponent_3011;
		case PComponentPort2EditPart.VISUAL_ID:
			return PComponentPort_3012;
		case PConnector2EditPart.VISUAL_ID:
			return PConnector_3013;
		case PConnectorRole2EditPart.VISUAL_ID:
			return PConnectorRole_3014;
		case PConstraintEditPart.VISUAL_ID:
			return PConstraint_3015;
		case PElementRolesEditPart.VISUAL_ID:
			return PElementRoles_4011;
		case PElementMultiplicityEditPart.VISUAL_ID:
			return PElementMultiplicity_4012;
		case PComponentPortDelegatedPortsEditPart.VISUAL_ID:
			return PComponentPortDelegatedPorts_4013;
		case PComponentPortAttachedRoleEditPart.VISUAL_ID:
			return PComponentPortAttachedRole_4014;
		case PConnectorRoleDelegatedRolesEditPart.VISUAL_ID:
			return PConnectorRoleDelegatedRoles_4015;
		}
		return null;
	}

}
